/**
 * 模块列表页JS
 * @type {string}
 */
function saveConfirm(url, params) {
    layer.confirm('是否确定提交？', function (index) {
        layer.close(index)
        save(url, params, true, null);
    });
}

function save(params, success, fail) {
    // 打开一个加载层
    var loadIndex = layer.msg('提交中', {
        time: 0, // 20s 后自动关闭
        icon: 16, shade: 0.5
    });
    $.post(__basePath + tabUrl() + "/save", params, function (data) {
        layer.close(loadIndex)
        if (data.code > 0) {
            if (success) {
                success(data)
            } else if (data.code !== -2) {
                layer.msg(data.msg, {icon: 1});
                setTimeout(function () {
                    closeTab()
                }, 1000)

            }
        } else {
            if (fail) {
                fail()
            } else {
                layer.msg(data.msg, {icon: 5});
            }
        }
    }, "json");
}

function closeTab() {
    var frame = self.frameElement;
    if (frame) {
        let tab = frame.getAttribute("tab")
        if (tab) {
            let pid = frame.getAttribute("pid")
            //关闭当前tab
            let ifragmentId = frame.id
            //通知对父级talbe进行刷新
            if (pid) top.reloadModule(pid)
            if (ifragmentId) {
                top.layui.element.tabChange('layadmin-layout-tabs', pid);
                top.layui.element.tabDelete('layadmin-layout-tabs', ifragmentId)
            }
        } else {
            window.parent.reloadTable()
            var index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
            parent.layer.close(index); // 再执行关闭
        }
    }
}
